package com.gitee.funcy.multiple.datasource.config.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * ｛这里添加描述｝
 *
 * @author funcy
 * @date 2019-09-04 11:32
 */
@Configuration
@ConfigurationProperties(prefix = "spring.datasource.druid")
public class AppDataSourceProperties {

    private Map<String, DataSourceConnectInfo> app = new LinkedHashMap<>();

    /**
     * 获取数据源名称列表
     * @return
     */
    public List<String> getDataSourceList() {
        Set<String> set = app.keySet();
        return new ArrayList<>(set);
    }

    /** 数据源连接的用户名 */
    public String getUsername(String dataSourceName) {
        return app.get(dataSourceName).getUsername();
    }

    /** 数据源连接的密码 */
    public String getPassword(String dataSourceName) {
        return app.get(dataSourceName).getPassword();
    }

    /** 数据源连接的url */
    public String getUrl(String dataSourceName) {
        return app.get(dataSourceName).getUrl();
    }

    public void setApp(Map<String, DataSourceConnectInfo> app) {
        this.app = app;
    }

    public Map<String, DataSourceConnectInfo> getApp() {
        return app;
    }

}
